package com.zsix.system.strategy.autoCopyFor;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
public class AutoCopyForContext {
    /**
     * 知会策略对象
     */
    private final List<AutoCopyStrategy> autoCopyStrategies;
    /**
     * 构造函数
     * @param autoCopyStrategies
     */
    public AutoCopyForContext(List<AutoCopyStrategy> autoCopyStrategies){
        this.autoCopyStrategies=autoCopyStrategies;
    }
    /**
     * server容器
     */
    private Map<String, AutoCopyStrategy> autoCopyStrategyMap = new HashMap<>();

    /**
     * 初始化
     */
    @PostConstruct
    public void init(){
        autoCopyStrategyMap=autoCopyStrategies.stream()
                .collect(Collectors.toMap(AutoCopyStrategy::getType, o -> o));
    }
    /**
     * 获取方法
     * @param serviceType
     * @return
     */
    public AutoCopyStrategy getService(String serviceType){
        return autoCopyStrategyMap.get(serviceType);
    }
}
